package com.paas.kafka.executor;

import com.alibaba.fastjson.JSON;
import com.paas.kafka.KafkaServiceStart;
import com.plat.paas.kafka.Message;
import com.plat.paas.kafka.MessageExecutor;
import org.apache.log4j.Logger;


public class MsgExecutor implements MessageExecutor{

	private final String module = MsgExecutor.class.getName();
	private static final Logger logger = Logger.getLogger(KafkaServiceStart.class);

	private static  int countMsg = 0;

    @Override
    public void execute(Message message) throws Exception {
    	
            switch (message.getTopic()) {
			case "test-topic":
				countMsg++;
				logger.info("Topic " + message.getTopic()+ ", countMsg = "+ countMsg + ", 获取到待消费的信息："+JSON.toJSONString(message));
				break;
			case "test1-topic":
				break;
			default:
				break;
			}
			if (countMsg == 3){
				throw  new Exception();
			}
    	/*
        for (int i = 0; i < 10000; i++) {
        	final String callMsg = " Remote call test " + JSON.toJSONString(message);
        	//System.out.println("======= " + callMsg);
        	Thread thread = new Thread(new Runnable() {
				
				@Override
				public void run() {
			        try {
						String ser = helloService.helloString(callMsg);
				        //System.out.println("并发测试 Thrift service = " + ser);
					} catch (TException e) {
						e.printStackTrace();
					}
				}
			});
        	thread.start();
		}*/

    }
    
    
}

